package sample.googlecode.genericdao.oldworld.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import sample.googlecode.genericdao.oldworld.dao.UserDAO;
import sample.googlecode.genericdao.oldworld.model.User;

import com.googlecode.genericdao.search.ISearch;
import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
@Service
public class UserServiceImpl implements UserService {
	
	UserDAO dao;

	@Autowired
	public void setDao(UserDAO dao) {
		this.dao = dao;
	}
	
	public void save(User user) {
		dao.save(user);
	}

	public List<User> findAll() {
		return dao.findAll();
	}

	public User findByName(String name) {
		if (name == null)
			return null;
		return dao.searchUnique(new Search().addFilterEqual("name", name));
	}

	public void flush() {
		dao.flush();
	}

	public List<User> search(ISearch search) {
		return dao.search(search);
	}

	public User findById(Long id) {
		return dao.find(id);
	}

	public void delete(Long id) {
		dao.removeById(id);
	}

	public SearchResult<User> searchAndCount(ISearch search) {
		return dao.searchAndCount(search);
	}

}
